Skip to content

fix(python): release GIL before blocking on tokio runtime#450

Merged
chaliy merged 1 commit intomainfrom
claude/fix-413-Y2nIj
Mar 1, 2026
Merged

fix(python): release GIL before blocking on tokio runtime#450
chaliy merged 1 commit intomainfrom
claude/fix-413-Y2nIj

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Mar 1, 2026

Summary

  • Wrap all rt.block_on() calls with py.detach() to release GIL before blocking
  • Prevents deadlock in multi-threaded Python when tool callbacks need to reacquire GIL
  • Fixes 5 call sites: PyBash::execute_sync, PyBash::reset, BashTool::execute_sync, BashTool::reset, ScriptedTool::execute_sync

Closes #413

Test plan

  • Concurrent thread tests for ScriptedTool, Bash, and BashTool validate no deadlock
  • cargo clippy and cargo fmt pass
  • cargo test -p bashkit-python passes

Wrap all rt.block_on() calls in py.detach() to release the GIL before
blocking. This prevents deadlock when tool callbacks call Python::attach()
to reacquire the GIL in multi-threaded scenarios.

Fixed in: PyBash::execute_sync, PyBash::reset, BashTool::execute_sync,
BashTool::reset, ScriptedTool::execute_sync.

https://claude.ai/code/session_01WZjYqxm5xMPAEe7FSHJkDy
@chaliy chaliy force-pushed the claude/fix-413-Y2nIj branch from 8959128 to e4e3508 Compare March 1, 2026 08:56
@chaliy chaliy merged commit aadf3d6 into main Mar 1, 2026
17 checks passed
@chaliy chaliy deleted the claude/fix-413-Y2nIj branch March 12, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[H-7] GIL deadlock risk in execute_sync Python binding

2 participants